#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <muParser.h>
#include "fourier.h"
#include "math.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QLayout* pLayout = new QBoxLayout(QBoxLayout::TopToBottom, ui->groupBox);
    ui->groupBox->setLayout(pLayout);

    this->pCanvas = new MyCanvas(ui->groupBox);
    pLayout->addWidget(this->pCanvas);
    ui->txtXinferior->setText("-6.28");
    ui->txtXsuperior->setText("6.28");
    ui->txtYinferior->setText("-1.5");
    ui->txtYsuperior->setText("1.5");
    ui->txtFuncion->setText("cos(x)");
    ui->txtM->setText("3");

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    this->pCanvas->pinto = true;
    this->recargarPropiedades();
}

void MainWindow::recargarPropiedades()
{
    this->pCanvas->x_cotainferior = ui->txtXinferior->text().toDouble();
    this->pCanvas->x_cotasuperior = ui->txtXsuperior->text().toDouble();
    this->pCanvas->y_cotainferior = ui->txtYinferior->text().toDouble();
    this->pCanvas->y_cotasuperior = ui->txtYsuperior->text().toDouble();
    char p[200];
    mu::Parser parser;
    parser.SetExpr(ui->txtFuncion->text().toStdString());
    if(this->pCanvas->funcion!=NULL)
        delete this->pCanvas->funcion;
    this->pCanvas->funcion=new Fourier(parser,"x",ui->txtM->text().toDouble());
    this->update();
}


